<?php

class myUser extends sfGuardSecurityUser
{
  public function getPresentations()
  {
    return Doctrine::getTable('BeamrPresentation')
      ->createQuery('p')
      ->where('p.user_id = ?', $this->getGuardUser()->getId())
      ->execute();
  }
  public function getPresentation($token)
  {
    $presentations = Doctrine::getTable('BeamrPresentation')
      ->createQuery('p')
      ->where('p.token = ?', $token)
      ->andWhere('p.user_id = ?', $this->getGuardUser()->getId())
      ->execute();
    if ($presentations) {
      return $presentations->getFirst();
    }
    else {
      return $presentations;
    }
  }
  public function getPublicPresentation($token)
  {
    $presentations = Doctrine::getTable('BeamrPresentation')
      ->createQuery('p')
      ->where('p.token = ?', $token)
      ->andWhere('p.user_id = ? OR p.is_public = ?', array($this->getGuardUser()->getId(), 1))
      ->execute();
    if ($presentations) {
      return $presentations->getFirst();
    }
    else {
      return $presentations;
    }
  }
}
